//
// GPSMapEdit
// (c) Konstantin Galichsky (kg@geopainting.com), 2007
//
// Highlight routing nodes by color.
//

# include "StdAfx.h"
# include "Resource.h"
# include "DrawNodes.h"
# include "Colors.h"
# include "Globals.h"

static CColors * g_pNodesColors;

static const COLORREF g_colNodes [] = {
	c_colBlack,
	c_colRed,
	c_colRed,
	c_colBlue,
	c_colWhite,
	c_colYellow,
	c_colGreen,
	c_colMagenta
};

void InitDrawNodes () {
	assert (g_pNodesColors == NULL);
	g_pNodesColors = new CColors;
	g_pNodesColors->LoadFromSetting ("RoutingNodesColors", g_colNodes, ARRAY_SIZE (g_colNodes));
}

void DestroyDrawNodes () {
	delete g_pNodesColors;
	g_pNodesColors = NULL;
}

bool AdjustColorsForRoutingNodes (HWND _hWnd) {
	assert (g_pNodesColors != NULL);

	const size_t cColors = g_pNodesColors->GetColors ();
	const char ** const strColorNames = (const char **) alloca (sizeof (char *)*cColors);

	fstring str [8];
	assert (cColors == ARRAY_SIZE (str));
	str [0].LoadFromResource (IDS_RNC_NO_RESTRICTIONS);
    str [1].LoadFromResource (IDS_RNC_HAS_RESTRICTIONS);
    str [2].LoadFromResource (IDS_RNC_MISPOSITION);
    str [3].LoadFromResource (IDS_RNC_CARDINALITY_1);
    str [4].LoadFromResource (IDS_RNC_CARDINALITY_2);
    str [5].LoadFromResource (IDS_RNC_CARDINALITY_3);
    str [6].LoadFromResource (IDS_RNC_CARDINALITY_4);
    str [7].LoadFromResource (IDS_RNC_CARDINALITY_5);

	for (size_t c = 0; c < __min (cColors, ARRAY_SIZE (str)); ++ c)
		strColorNames [c] = str [c].c_str ();

	if (g_pNodesColors->Adjust (_hWnd, g_colNodes, strColorNames, cColors)) {
		g_pNodesColors->SaveToSetting ("RoutingNodesColors");
		return true;
	}
	return false;
}

HBRUSH NodeCardinalityToBrush (size_t _cCardinality) {
	assert (g_pNodesColors != NULL);

	return g_pNodesColors->GetBrush (__min (_cCardinality, 5) + 2);
}

HPEN NodeContourPen (bool _bHasRestrictions) {
	return g_pNodesColors->GetPen (_bHasRestrictions ? 1 : 0);
}
